﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ndo.Maths
{
    public class Factorial
    {
        private static List<int> cache;
        private static List<long> cache64;
        private static List<float> cachef;
        private static List<double> cached;
        static Factorial()
        {
            cache = new List<int>();
            cache.Add(1);
            cache64 = new List<long>();
            cache64.Add(1);
            cachef = new List<float>();
            cachef.Add(1);
            cached = new List<double>();
            cached.Add(1);
        }
        public static int Get(int i)
        {
            lock (typeof (Factorial))
            {
                while (cache.Count <= i)
                {
                    cache.Add(cache[cache.Count - 1]*cache.Count);
                }
                return cache[i];
            }
        }

        public static long Get64(int i)
        {
            lock (typeof (Factorial))
            {
                while (cache64.Count <= i)
                {
                    cache64.Add(cache64[cache64.Count - 1] * cache64.Count);
                }
                return cache64[i];
            }
        }

        public static float GetFloat(int i)
        {
            lock (typeof (Factorial))
            {
                while (cachef.Count <= i)
                {
                    cachef.Add(cachef[cachef.Count - 1]*cachef.Count);
                }
                return cachef[i];
            }
        }

        public static double GetDouble(int i)
        {
            lock (typeof (Factorial))
            {
                while (cached.Count <= i)
                {
                    cached.Add(cached[cached.Count - 1]*cached.Count);
                }
                return cached[i];
            }
        }
    }
}
